package com.ruoyi.business.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.business.domain.dto.TrainTicketGroupDTO;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableSupport;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.DailyTrainTicket;
import com.ruoyi.business.service.IDailyTrainTicketService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 余票信息Controller
 * 
 * @author ruoyi
 * @date 2025-03-06
 */
@RestController
@RequestMapping("/business/daily-train-ticket")
public class DailyTrainTicketController extends BaseController
{
    @Autowired
    private IDailyTrainTicketService dailyTrainTicketService;

    /**
     * 查询余票信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:daily-train-ticket:list')")
    @GetMapping("/list")
    public TableDataInfo list(DailyTrainTicket dailyTrainTicket)
    {
        startPage();
        List<DailyTrainTicket> list = dailyTrainTicketService.selectDailyTrainTicketList(dailyTrainTicket);
        return getDataTable(list);
    }

    /**
     * 按车次分组查询余票信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:daily-train-ticket:list')")
    @GetMapping("/listByGroup")
    public TableDataInfo listByGroup(DailyTrainTicket dailyTrainTicket) {
        // 获取分页信息
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();

        // 调用服务方法获取分页数据
        return dailyTrainTicketService.listDailyTrainTicketByTrainGroup(dailyTrainTicket, pageNum, pageSize);
    }

    /**
     * 导出余票信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:daily-train-ticket:export')")
    @Log(title = "余票信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DailyTrainTicket dailyTrainTicket)
    {
        List<DailyTrainTicket> list = dailyTrainTicketService.selectDailyTrainTicketList(dailyTrainTicket);
        ExcelUtil<DailyTrainTicket> util = new ExcelUtil<DailyTrainTicket>(DailyTrainTicket.class);
        util.exportExcel(response, list, "余票信息数据");
    }

    /**
     * 获取余票信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:daily-train-ticket:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dailyTrainTicketService.selectDailyTrainTicketById(id));
    }

    /**
     * 新增余票信息
     */
    @PreAuthorize("@ss.hasPermi('business:daily-train-ticket:add')")
    @Log(title = "余票信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DailyTrainTicket dailyTrainTicket)
    {
        return toAjax(dailyTrainTicketService.insertDailyTrainTicket(dailyTrainTicket));
    }

    /**
     * 修改余票信息
     */
    @PreAuthorize("@ss.hasPermi('business:daily-train-ticket:edit')")
    @Log(title = "余票信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DailyTrainTicket dailyTrainTicket)
    {
        return toAjax(dailyTrainTicketService.updateDailyTrainTicket(dailyTrainTicket));
    }

    /**
     * 删除余票信息
     */
    @PreAuthorize("@ss.hasPermi('business:daily-train-ticket:remove')")
    @Log(title = "余票信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dailyTrainTicketService.deleteDailyTrainTicketByIds(ids));
    }
}
